import {
  Body,
  Controller,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { UserService } from '@/pmp/system/services/user/user.service';
import { UserPlusDto } from '@/pmp/dto/user/user.plus.dto';
import { UserQueryDto } from '@/pmp/dto/user/user.query.dto';
import { PageDto } from '@/pmp/dto/page.dto';
import { DeleteDto } from '@/pmp/dto/delete.dto';
import { FileInterceptor } from '@nestjs/platform-express';

@ApiTags('用户相关接口')
@Controller('/system/user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @ApiOperation({ summary: '用户添加' })
  @Post(`/plus`)
  plus(@Body() body: UserPlusDto) {
    return this.userService.plus(body);
  }

  @ApiOperation({ summary: '用户删除' })
  @Post(`/delete`)
  delete(@Body() body: DeleteDto) {
    return this.userService.delete(body);
  }

  @ApiOperation({ summary: '用户修改' })
  @Post(`/update`)
  update(@Body() body: any) {
    return this.userService.update(body);
  }

  @ApiOperation({ summary: '分页查询' })
  @Post(`/pageList`)
  pageList(@Body() body: PageDto<UserQueryDto>) {
    return this.userService.pageList(body);
  }

  @ApiOperation({ summary: '用户导入' })
  @Post(`/export`)
  @UseInterceptors(FileInterceptor('file'))
  async export(@UploadedFile() file: Express.Multer.File) {
    return await this.userService.export(file);
  }
}
